import request from '@/utils/request'
import { camelCaseObject } from '@/libs/object'

const AUTH_PREFIX_V1 = `/api/v1/dns`

export function getDnsDomainsTree() {
  return request.get(`${AUTH_PREFIX_V1}/domains/tree`).then(res => camelCaseObject(res))
}

export function getDnsDomainList() {
  return request.get(`${AUTH_PREFIX_V1}/domains`).then(res => camelCaseObject(res))
}

export function getDnsDomainRecords(dnsDomainId) {
  return request.get(`${AUTH_PREFIX_V1}/domains/${dnsDomainId}/records`).then(res => camelCaseObject(res))
}

export function getDnsRecordPageList(params) {
  return request.get(`${AUTH_PREFIX_V1}/records/page`, { params }).then(res => camelCaseObject(res))
}

export function getDnsRecordAllList(params) {
  return request.get(`${AUTH_PREFIX_V1}/records/all`, { params }).then(res => camelCaseObject(res))
}

export function getDnsRecordSimpleList(params) {
  return request.get(`${AUTH_PREFIX_V1}/records/simple`, { params }).then(res => camelCaseObject(res))
}

export function enableDnsRecord(recordId) {
  return request.put(`${AUTH_PREFIX_V1}/records/${recordId}/enable`).then(res => camelCaseObject(res))
}

export function disableDnsRecord(recordId) {
  return request.put(`${AUTH_PREFIX_V1}/records/${recordId}/disable`).then(res => camelCaseObject(res))
}

export function updateDnsRecord(recordId, params) {
  return request.put(`${AUTH_PREFIX_V1}/records/${recordId}`, params).then(res => camelCaseObject(res))
}

export function createDnsRecord(params) {
  return request.post(`${AUTH_PREFIX_V1}/records`, params).then(res => camelCaseObject(res))
}

export function deleteDnsRecord(record_id) {
  return request.delete(`${AUTH_PREFIX_V1}/records/${record_id}`).then(res => camelCaseObject(res))
}
